﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathNet.Numerics;
using System.Drawing;

namespace ParticleTracker
{
    class ComplexFrame
    {
        ParticleFrame frame;
        Complex[,] data = null;
        public ComplexFrame(ParticleFrame frame)
        {
            this.frame = frame;
        }
        public Complex[,] ColorArrayToComplexArray(Color[,] array)
        {
            Complex[,] complexArray = new Complex[array.GetLength(0), array.GetLength(1)];
            for(int i = 0; i<array.GetLength(0); i++)
            {
                for(int j = 0; j<array.GetLength(1); j++)
                {
                    if( array[i,j].R > 0)
                    {
                        complexArray[i, j] = 1;
                    }
                }
            }
            
            return complexArray;
        }
        public ComplexFrame GetComplexFrame()
        {
            frame.Area = frame.RectangleFull;
            //frame.Monochrome();
            //frame.AdaptiveThreshold();
            Color[,] cc = frame.get();
            this.data = ColorArrayToComplexArray(cc);
            return this;
        }
        public Complex[,] GetComplexRect(Rectangle r)
        {
            if (data == null)
            {
                this.GetComplexFrame();
            }
            Complex[,] array = new Complex[r.Height, r.Width];
            for (int i = r.Y; i < r.Y + r.Height; i++)
            {
                for (int j = r.X; j < r.X + r.Width; j++)
                {
                    array[i-r.Y, j - r.X] = this.data[j, i];
                }
            }
            return array;
        }
    }
    class SubFrame : Piece
    {
        public SubFrame(ComplexFrame frame, Point p)
        {
            /// calculate subframe rectangle based on p from frame
        }
    }
}
